﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace SanctusSoftware.CcliSongSelectLib.Management
{
    public class FileToLibraryCollection : ObservableCollection<FileToLibrary>
    {
        
        #region Properties

        public FileToLibrary this[string filePath]
        {
            get
            {
                return this.First(item => item.Path == filePath);
            }
        }

        #endregion
        
        #region Methods

        public FileToLibrary Add(string filePath, Library library)
        {
            FileToLibrary f = new FileToLibrary();
            f.Path = filePath;
            f.Libraries.Add(library);
            this.Add(f);
            return f;
        }

        public bool Contains(string filePath)
        {
            return (this.FirstOrDefault(item => item.Path == filePath) != null);
        }
        
        #endregion


        

        public bool Contains(string filePath, Library library)
        {
            if (!this.Contains(filePath))
            {
                return false;
            }
            if (!this[filePath].Libraries.Contains(library))
            {
                return false;
            }
            return true;
        }
    }
}
